/**
 * VUEshop
 * ============================================================================
 * * 版权所有 2015-2027 深圳搜豹网络科技有限公司，并保留所有权利。
 * 网站地址: http://www.vueshop.com.cn
 * ----------------------------------------------------------------------------
 * 这不是一个自由软件！您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
 * 不允许对程序代码以任何形式任何目的的再发布。
 * ============================================================================
 * $Author: 沈小白 2020-07-22 $
 */<template> 
	<view>
		<view class="panel pd-bg-fff">
			<form @submit="submitWithdrawals">
				<view class="apply-item">
					<view class="title">提现金额 : </view>
					
					<input name="money" v-model="params.money" :placeholder="'可提现金额 :'+filter(userInfo.user_money)+'元'" type="digit"></input>
				</view>
				<view class="apply-item">
					<view class="title">银行名称 : </view>
					<input name="bank_name" v-model="params.bank_name" placeholder="如 : 工商银行,支付宝,微信" type="text">

					</input>
				</view>
				<view class="apply-item">
					<view class="title">收款账号 : </view>
					<input name="account_bank" v-model="params.bank_card" placeholder="收款账号" type="number">

					</input>
				</view>
				<view class="apply-item">
					<view class="title">开户号 : </view>
					<input name="account_name" v-model="params.realname" placeholder="持卡人姓名" type="text"></input>
				</view>
				<view class="apply-item">
					<view class="title">支付密码 : </view>
					<input name="paypwd" v-model="pay_pwd" placeholder="支付密码" type="password"></input>
				</view>
				<!-- <view class="apply-item">
					<view class="title">验证码 : </view>
					<input class="v-code-text" name="verify_code" placeholder="请输入验证码" type="text"></input>
					<view @tap="getCapache" class="v-code">
						
						 <image  class="wh100" :src="hostUrl+codeUrl" ></image>
					</view>
				</view> -->
				<button class="apply-btn" form-type="submit" role="button" aria-disabled="false">
					提交申请

				</button>
			</form>
		</view>
	</view>
</template>

<script>
	const globalData=getApp().globalData//从app.vue获取用户信息
	import config from "@/api/config.js";
	import common from "@/common/common.js";
	import Md from "md5";
	import {getUserInfo,postWithdrawal} from "@/api/api.js";
	// import {verification} from "@/api/api.js";
	export default {
		data() {
			return {
				hostUrl: config.host,
				userInfo:"",//用户信息
				codeUrl:"/user/verification",
				pay_pwd:"",
				params:{
					"money":"",//金额
					"bank_name":"",//银行名称
					"bank_card":"",//银行卡号
					"realname":"",//开户名
					"pay_pwd":"",//支付密码
					"type":0,//余额提现
				}
			};
		},
		onLoad(){
			if(this.userInfo==""){
				this.getUserInfo()
			}
			this.userInfo=globalData.userInfo;
		},
		methods:{
			/*用户信息*/
			getUserInfo(){
				getUserInfo().then(res=>{
					if(res){
						// console.log(res)
						if(res.head_pic.indexOf("public")==1){ //判断头像 是否有 域名
							let hostUrl=config.host;//路径前缀
							res.head_pic=hostUrl+res.head_pic;//路径前缀
						}
						this.userInfo=res;
						getApp().globalData.userInfo=res;
					}
				})
			},
			/*提现*/ 
			submitWithdrawals(){
				if(this.params.money==""){
					common.toast("none","请输入提现金额",2000)
					return false;
				}
				if(this.params.bank_name==""){
					common.toast("none","请输入银行名称",2000)
					return false;
				}
				if(this.params.bank_card==""){
					common.toast("none","请输入银行卡号",2000)
					return false;
				}
				if(this.params.realname==""){
					common.toast("none","请输入开户名",2000)
					return false;
				}
				if(this.pay_pwd==""){
					common.toast("none","请输入支付密码",2000)
					return false;
				}
				this.params.pay_pwd=Md("TPSHOP"+this.pay_pwd)
				this.postWithdrawal(this.params)
			},
			// /*切换图片验证码*/
			// getCapache(){
			// 	this.codeUrl=`/user/verification?t=${Math.random()}`
			// },
			/*提现方法*/ 
			postWithdrawal(params){
				postWithdrawal(params).then(res=>{
					if(res.status==1){
						common.toast("none",res.msg,2000)
						setTimeout(()=>{
							uni.navigateTo({
								url:`/pages/user/account/account?status=3`
							})
						},2000)
					}else{
						common.toast("none",res.msg,2000)
					}
				})
			},
			/*保留两位小数*/
			filter(e) {
				let num = parseFloat(e).toFixed(2)
				return num;
			},
		}
	}
</script>

<style lang="scss">
	/* withdrawals.wxss */
	.panel {
		padding-bottom: 50rpx;
		width: 710rpx;
		margin: 0 auto;
		border-radius: 10rpx;
		box-sizing: border-box;
		margin-top: 20rpx;
	}

	.apply-item {
		display: flex;
		align-items: center;
		font-size: 28rpx;
		height: 88rpx;
		border-bottom: 1px solid #f3f3f3;
	}

	.title {
		color: #333;
		margin-right: 20rpx;
	}

	input {
		color: #666;
		width: 500rpx;
	}

	.v-code-text {
		width: 220rpx;
	}

	.v-code {
		width: 260rpx;
		height: 60rpx;
	}

	.apply-btn {
		margin: 60rpx auto 0;
		width: 580rpx;
		height: 88rpx;
		font-size: 28rpx;
		line-height: 88rpx;
		text-align: center;
		color: #fff;
		background-color: #ff3b3b;
		border-radius: 10rpx;
	}
</style>
